<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Universal.css">
</head>
<body>
    
    <div id="cnblogs_post_body" class="blogpost-body">
        <p>本项目为JAVA基础综合项目，主要包括：</p>
    <p>熟练View层、Service层、Dao层之间的方法相互调用操作、熟练dbutils操作数据库表完成增删改查。</p>
    <h2><strong>项目功能分析</strong></h2>
    <p><strong><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721094035068-520206082.png" alt=""></strong></p>
    <p>&nbsp;</p>
    <ul>
    <li class="15">&nbsp;查询账务</li>
    <li class="15">多条件组合查询账务</li>
    <li class="15">添加账务</li>
    <li class="15">编辑账务</li>
    <li class="15">删除账务</li>
    </ul>
    <h2><strong>项目环境搭建</strong></h2>
    <h3>技术选型和jar包介绍</h3>
    <p>每个项目都要使用一些已经成熟的技术，它们通常是由一些专业组织或团队所提供的开源免费技术。在今后的学习过程中，我们会逐渐对这些专业组织有所了解。本项目中使用的技术如下：</p>
    <p>apache的commons组件：</p>
    <ul>
    <li>commons-dbutils-1.6.jar：封装并简化了JDBC；</li>
    <li>commons-dbcp-1.4.jar：apache commons提供的数据库连接池组件，命名为DBCP；</li>
    <li>commons.pool-1.5.6.jar：DBCP连接池依赖该jar包；</li>
    </ul>
    <p>mysql-connector-java-5.1.7-bin.jar：MySQL的JDBC驱动包，用JDBC连接MySQL数据库必须使用该JAR包。</p>
    <h3>工具类介绍</h3>
    <p>每个项目都会用到一些工具类，本项目也不例外。我们不会教大家如何实现这些类，而是让大家知道在项目我们如何使用这些工具类，下面是本项目中所使用的工具类以及介绍：</p>
    <p>JDBCUtils：用来创建数据库连接池对象；不懂请移步<a href="http://www.cnblogs.com/ginb/p/7211455.html" target="_blank">这里</a></p>
    <p>JDBCUtils.java</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> JDBCUtils {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">final</span> String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver"<span style="color: rgba(0, 0, 0, 1)">;
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">final</span> String URL = "jdbc:mysql://localhost:3306/gjp"<span style="color: rgba(0, 0, 0, 1)">;
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">final</span> String USERNAME = "root"<span style="color: rgba(0, 0, 0, 1)">;
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">final</span> String PASSWORD = "123456"<span style="color: rgba(0, 0, 0, 1)">;
        
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">static</span> BasicDataSource dataSource = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BasicDataSource();
        </span><span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> {
            dataSource.setDriverClassName(DRIVER_CLASS_NAME);
            dataSource.setUrl(URL);
            dataSource.setUsername(USERNAME);
            dataSource.setPassword(PASSWORD);
        }
        
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> DataSource getDataSource() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> dataSource;
        }
    }</span></pre>
    </div>
    <h3>数据表创建</h3>
    <p>对一个项目而言，表设计是非常重要的，因为应用程序中所有的操作都是基于数据库表而进行的，所以我们第一步就是创建数据库表。管家婆项目的数据库设计很简单，下面是创建库及表的SQL语句：</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      创建管家婆的数据库
      名字 gjp
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">DATABASE</span><span style="color: rgba(0, 0, 0, 1)"> gjp;
    
    </span><span style="color: rgba(0, 0, 255, 1)">USE</span><span style="color: rgba(0, 0, 0, 1)"> gjp;
    
    </span><span style="color: rgba(0, 128, 128, 1)">/*</span><span style="color: rgba(0, 128, 128, 1)">
      创建数据表,表名账务
      字段,列
      主键
      分类名称  可变字符
      金额  double
      账户  可变字符 (支付,收入方法)
      创建日期 date
      账务描述 可变字符
    </span><span style="color: rgba(0, 128, 128, 1)">*/</span>
    
    <span style="color: rgba(0, 0, 255, 1)">CREATE</span> <span style="color: rgba(0, 0, 255, 1)">TABLE</span><span style="color: rgba(0, 0, 0, 1)"> gjp_zhangwu(
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 主键</span>
       zwid <span style="color: rgba(0, 0, 255, 1)">INT</span> <span style="color: rgba(0, 0, 255, 1)">PRIMARY</span> <span style="color: rgba(0, 0, 255, 1)">KEY</span><span style="color: rgba(0, 0, 0, 1)"> AUTO_INCREMENT,
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 分类名称   </span>
       flname <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">200</span><span style="color: rgba(0, 0, 0, 1)">),
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 金额</span>
       <span style="color: rgba(0, 0, 255, 1)">money</span> <span style="color: rgba(0, 0, 255, 1)">DOUBLE</span><span style="color: rgba(0, 0, 0, 1)">,
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 账户</span>
       zhanghu <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">100</span><span style="color: rgba(0, 0, 0, 1)">),
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 创建日期</span>
    <span style="color: rgba(0, 0, 0, 1)">   createtime DATE,
       </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 账务描述</span>
       description  <span style="color: rgba(0, 0, 255, 1)">VARCHAR</span>(<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span><span style="color: rgba(0, 0, 0, 1)">)
    );
    </span><span style="color: rgba(0, 0, 255, 1)">SELECT</span> <span style="color: rgba(128, 128, 128, 1)">*</span> <span style="color: rgba(0, 0, 255, 1)">FROM</span><span style="color: rgba(0, 0, 0, 1)"> gjp_zhangwu
    
    </span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 写入测试的数据</span>
    <span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">247</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">交通银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-03-02</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">家庭聚餐</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工资收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">12345</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-03-15</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">开工资了</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">服装支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1998</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-04-02</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">买衣服</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">325</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-06-18</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">朋友聚餐</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">股票收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工商银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-28</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">股票大涨</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">6</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">股票收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工商银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-28</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">股票又大涨</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">7</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工资收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">交通银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-28</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">又开工资了</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">礼金支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-28</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">朋友结婚</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">9</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">其他支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1560</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-29</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">丢钱了</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">10</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">交通支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2300</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">交通银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-29</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">油价还在涨啊</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">11</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">吃饭支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工商银行</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-29</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">又吃饭</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">12</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工资收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-30</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">开资</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">13</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">交通支出</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-30</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">机票好贵</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
    </span><span style="color: rgba(0, 0, 255, 1)">INSERT</span>  <span style="color: rgba(0, 0, 255, 1)">INTO</span> gjp_zhangwu(zwid,flname,<span style="color: rgba(0, 0, 255, 1)">money</span>,zhangHu,createtime,description) <span style="color: rgba(0, 0, 255, 1)">VALUES</span> (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">14</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">工资收入</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5000</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">现金</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">2016-10-30</span><span style="color: rgba(255, 0, 0, 1)">'</span>,<span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">又开资</span><span style="color: rgba(255, 0, 0, 1)">'</span>);</pre>
    </div>
    <h3><strong>项目分层（分包）的作用</strong></h3>
    <p>程序为什么要分包分层?</p>
    <p>以顾客去饭店吃饭案例分析一下：</p>
    <p>小饭店: 一个服务员搞定(接待顾客\点菜\炒菜)</p>
    <p>大饭店:</p>
    <ul>
    <li>迎宾员(是否有预定\ 询问吃中餐还是西餐或者烧烤等\ 几位用餐 \ 领路到指定的包间\ 找点菜员为顾客点菜 )</li>
    <li>点菜员(记录顾客点餐内容\ 记录是否有忌口等问题\ 找厨师为顾客炒菜)</li>
    <li>厨师(按照顾客菜肴清单,进行炒菜)</li>
    </ul>
    <p>通过案例发现，当程序规模小的时候，可以一个人全部完成；但程序规模大的时候，一个人难以完成，这时，要采用多人合作的方式来完成程序开发。多人合作方式将会碰到工作任务分配问题，这时我们会想，每个人负责完成项目的一块内容就可以了。那么，这一块块内容的划分，就需要我们采用分层（分包）的方式完成了。</p>
    <p>通过下图（用户注册功能）来讲解下，项目中常见的分层（分包）。</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721095017052-1390346769.png" alt=""></p>
    <p>view层作用: 视图层,即项目中的界面</p>
    <p>controller层作用: 控制层, 获取界面上的数据,为界面设置数据; 将要实现的功能交给业务层处理</p>
    <p>service层作用: 业务层, 功能的实现, 与controller控制层和数据访问层DAO交互, 将对数据库的操作交给DAO数据访问层来处理</p>
    <p>dao层作用: 数据访问层, 用来操作数据库表的数据</p>
    <p>db数据库: 这里指MySQL</p>
    <p>domain 实体包: 存放JavaBean</p>
    <p>tools工具包:存放项目中使用到的工具类</p>
    <p>test 测试包: 存放项目功能测试的代码</p>
    <h3>工程创建及包管理</h3>
    <ul>
    <li>使用&nbsp;<span class="link_title">IntelliJ IDEA</span>创建Java工程，命名为gjp</li>
    <li>创建工程包</li>
    </ul>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.app: 存放main方法类；&nbsp;</p>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.domain: 存放JavaBean；&nbsp;</p>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.view: 存放界面，及表现层类；&nbsp;</p>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.service: 存放业务层类；&nbsp;</p>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.dao: 存放数据访问层类;&nbsp;</p>
    <p class="_mce_tagged_br" style="margin-left: 60px">cn.itcast.gjp.tools:存放工具类</p>
    <ul>
    <li>创建lib文件夹，用来存储使用的jar包</li>
    </ul>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721100940740-628484853.png" alt=""></p>
    <p>把jar包拷贝到lib目录下，并</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721102125521-2116811721.png" alt=""></p>
    <p>选择Dependencies——&gt;点击+按钮——&gt;选择JARS or dirretories...</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721102222130-144004646.png" alt=""></p>
    <p>选择jar包——&gt;OK</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721102356396-1996889334.png" alt=""></p>
    <p>Apply——&gt;OK</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721102446786-484703025.png" alt=""></p>
    <h2><span style="font-size: 1.5em">功能模块</span></h2>
    <h3><strong style="font-size: 1.17em">相关类创建</strong></h3>
    <p>完成本项目中类的创建，无需在类中添加代码。</p>
    <p>复制已编写好的工具类JDBCUtils.java 到 tools包中；</p>
    <div class="cnblogs_code"><img id="code_img_closed_32ae71d2-0617-4e52-8a46-b7c5cf87bdcf" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_32ae71d2-0617-4e52-8a46-b7c5cf87bdcf" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_32ae71d2-0617-4e52-8a46-b7c5cf87bdcf" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.tools;
    </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
     *  使用DBCP实现数据库的连接池
     *  连接池配置,自定义类,
     *  最基本四项完整
     *  对于数据库连接池其他配置,自定义
     </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    
    <span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> org.apache.commons.dbcp.BasicDataSource;
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> javax.sql.DataSource;
    
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> JDBCUtils {
        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建出BasicDataSource类对象</span>
        <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">static</span> BasicDataSource datasource = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BasicDataSource();
    
        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">静态代码块,对象BasicDataSource对象中的配置,自定义</span>
        <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">数据库连接信息,必须的</span>
            datasource.setDriverClassName("com.mysql.jdbc.Driver"<span style="color: rgba(0, 0, 0, 1)">);
            datasource.setUrl(</span>"jdbc:mysql://localhost:3306/gjp"<span style="color: rgba(0, 0, 0, 1)">);
            datasource.setUsername(</span>"root"<span style="color: rgba(0, 0, 0, 1)">);
            datasource.setPassword(</span>"123456"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">对象连接池中的连接数量配置,可选的</span>
            datasource.setInitialSize(10);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">初始化的连接数</span>
            datasource.setMaxActive(8);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">最大连接数量</span>
            datasource.setMaxIdle(5);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">最大空闲数</span>
            datasource.setMinIdle(1);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">最小空闲</span>
    <span style="color: rgba(0, 0, 0, 1)">    }
    
        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">定义静态方法,返回BasicDataSource类的对象</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> DataSource getDataSource() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> datasource;
        }
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">JDBCUtils</span></div>
    <p>在app包中，创建类MainApp.java，编写main主方法，用来完成本项目的启动</p>
    <div class="cnblogs_code"><img id="code_img_closed_d477ac52-db98-4f79-b144-3dd77aa55e82" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_d477ac52-db98-4f79-b144-3dd77aa55e82" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_d477ac52-db98-4f79-b144-3dd77aa55e82" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.app;
    
    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
     * 程序入口
     </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MainApp {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
            
        }
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">MainApp</span></div>
    <p>在domain包中，创建类ZhangWu.java，它是用来封装账务信息的JavaBean。</p>
    <p>JavaBean是指的是Java中的类，该类中的成员变量与数据库表中的字段相对应（变量名对应数据库表字段名、变量数据类型对应数据库表字段类型），并提供空参数构造方法、set、get方法。</p>
    <p>我们现在来完成账务类的代码编写，如下：</p>
    <div class="cnblogs_code"><img id="code_img_closed_de87b268-fd00-45fd-9925-a454c360d1bc" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_de87b268-fd00-45fd-9925-a454c360d1bc" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_de87b268-fd00-45fd-9925-a454c360d1bc" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.domain;
    
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWu {
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)">  zwid;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String flname;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">double</span><span style="color: rgba(0, 0, 0, 1)">  money;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String zhanghu;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String createtime;
        </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String description;
    
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> ZhangWu(<span style="color: rgba(0, 0, 255, 1)">int</span> zwid, String flname, <span style="color: rgba(0, 0, 255, 1)">double</span><span style="color: rgba(0, 0, 0, 1)"> money, String zhanghu, String createtime, String description) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.zwid =<span style="color: rgba(0, 0, 0, 1)"> zwid;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.flname =<span style="color: rgba(0, 0, 0, 1)"> flname;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.money =<span style="color: rgba(0, 0, 0, 1)"> money;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.zhanghu =<span style="color: rgba(0, 0, 0, 1)"> zhanghu;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.createtime =<span style="color: rgba(0, 0, 0, 1)"> createtime;
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.description =<span style="color: rgba(0, 0, 0, 1)"> description;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWu() {
    
        }
        @Override
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String toString() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span> "Zhangwu [zwid=" + zwid + ", flname=" + flname + ", money=" + money + ", zhanghu=" +<span style="color: rgba(0, 0, 0, 1)"> zhanghu
                    </span>+ ", createtime=" + createtime + ", description=" + description + "]"<span style="color: rgba(0, 0, 0, 1)">;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> getZwid() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> zwid;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setZwid(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> zwid) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.zwid =<span style="color: rgba(0, 0, 0, 1)"> zwid;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String getFlname() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> flname;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> setFlname(String flname) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.flname =<span style="color: rgba(0, 0, 0, 1)"> flname;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">double</span><span style="color: rgba(0, 0, 0, 1)"> getMoney() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> money;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> setMoney(<span style="color: rgba(0, 0, 255, 1)">double</span><span style="color: rgba(0, 0, 0, 1)"> money) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.money =<span style="color: rgba(0, 0, 0, 1)"> money;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String getZhanghu() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> zhanghu;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> setZhanghu(String zhanghu) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.zhanghu =<span style="color: rgba(0, 0, 0, 1)"> zhanghu;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String getCreatetime() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> createtime;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> setCreatetime(String createtime) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.createtime =<span style="color: rgba(0, 0, 0, 1)"> createtime;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String getDescription() {
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> description;
        }
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> setDescription(String description) {
            </span><span style="color: rgba(0, 0, 255, 1)">this</span>.description =<span style="color: rgba(0, 0, 0, 1)"> description;
        }
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">ZhangWu</span></div>
    <p>在dao包中，创建类ZhangWuDao.java，给ZhangWuDao类添加一个成员变量QueryRunner对象，因为我们使用dbutils来操作数据库。</p>
    <div class="cnblogs_code"><img id="code_img_closed_14320bf3-3658-4684-b8ff-fec73a23586a" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_14320bf3-3658-4684-b8ff-fec73a23586a" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_14320bf3-3658-4684-b8ff-fec73a23586a" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.dao;
    
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.tools.JDBCUtils;
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> org.apache.commons.dbutils.QueryRunner;
    
    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
     *  实现对数据表 gjp_zhangwu 数据增删改查操作
     *  dbuils工具类完成,类成员创建QueryRunner对象,指定数据源
     *</span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWuDao {
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> QueryRunner qr = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> QueryRunner(JDBCUtils.getDataSource());
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">ZhangWuDao </span></div>
    <p>在service包中，创建类ZhangWuService.java，给ZhangWuService类添加一个类型为ZhangWuDao的成员变量，因为service依赖dao。</p>
    <div class="cnblogs_code"><img id="code_img_closed_a86e3fee-3102-4023-848a-fdaf44be2181" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_a86e3fee-3102-4023-848a-fdaf44be2181" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_a86e3fee-3102-4023-848a-fdaf44be2181" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.service;
    
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.dao.ZhangWuDao;
    
    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
     *  业务层类
     *  接收上一层,控制层controller的数据
     *  经过计算,传递给dao层,操作数据库
     *  调用dao层中的类,类成员位置,创建Dao类的对象
     </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWuService {
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> ZhangWuDao dao = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWuDao();
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">ZhangWuService</span></div>
    <p>在view包中，创建类MainView.java，给MainView类添加一个类型为ZhangWuService的成员变量，因为本项目中view依赖service。</p>
    <div class="cnblogs_code"><img id="code_img_closed_6acaaf93-3689-4af3-8fa5-67a7c0a4a8b7" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_6acaaf93-3689-4af3-8fa5-67a7c0a4a8b7" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_6acaaf93-3689-4af3-8fa5-67a7c0a4a8b7" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 0, 255, 1)">package</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.view;
    
    </span><span style="color: rgba(0, 0, 255, 1)">import</span><span style="color: rgba(0, 0, 0, 1)"> cn.itcast.gjp.service.ZhangWuService;
    
    </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
     *  视图层,用户看到和操作的界面
     </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MainView {
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> ZhangWuService service = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWuService();
    }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">MainView </span></div>
    <h3>功能界面菜单</h3>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721105139443-220325092.png" alt=""></p>
    <p>界面菜单的完成，是项目编写的第一步。我们通过输出语句，完成界面菜单的输出，之后再根据输入的功能序号，进行对应功能的调用执行。</p>
    <p><strong style="font-size: 1em">功能实现步骤</strong></p>
    <p>&nbsp;编写MainView类run方法</p>
    <ol>
    <li>完成功能界面菜单显示</li>
    <li>接收键盘输入的功能选项</li>
    <li>根据选项值，调用对应的功能方法</li>
    </ol>
    <p>编写MainApp类的main主方法</p>
    <p>调用MainView类中run方法，实现将程序执行起来，显示功能界面菜单。</p>
    <p><strong>&nbsp;功能实现代码</strong></p>
    <p>&nbsp;1、在view包MainView类中编写run方法</p>
    <div class="cnblogs_code"><img id="code_img_closed_59aa59e9-5e43-4df1-92c3-a17aeec4ff91" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_59aa59e9-5e43-4df1-92c3-a17aeec4ff91" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_59aa59e9-5e43-4df1-92c3-a17aeec4ff91" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         *  实现界面效果
         *  接收用户的输入
         *  根据数据,调用不同的功能方法
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> run(){
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建Scanner类对象,反复键盘输入</span>
            Scanner sc = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in);
            </span><span style="color: rgba(0, 0, 255, 1)">while</span>(<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">){
                System.out.println(</span>"---------------管家婆家庭记账软件---------------"<span style="color: rgba(0, 0, 0, 1)">);
                System.out.println(</span>"1.添加账务　2.编辑账务　3.删除账务　4.查询账务　5.退出系统"<span style="color: rgba(0, 0, 0, 1)">);
                System.out.println(</span>"请输入要操作的功能序号[1-5]:"<span style="color: rgba(0, 0, 0, 1)">);
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">接收用户的菜单选择</span>
                <span style="color: rgba(0, 0, 255, 1)">int</span> choose =<span style="color: rgba(0, 0, 0, 1)"> sc.nextInt();
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">对选择的菜单判断,调用不同的功能</span>
                <span style="color: rgba(0, 0, 255, 1)">switch</span><span style="color: rgba(0, 0, 0, 1)">(choose){
                </span><span style="color: rgba(0, 0, 255, 1)">case</span> 1<span style="color: rgba(0, 0, 0, 1)">:
                   </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 选择添加账务,调用添加账务的方法</span>
    <span style="color: rgba(0, 0, 0, 1)">                addZhangWu();
                    </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">case</span> 2<span style="color: rgba(0, 0, 0, 1)">:
                    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 选择的编辑账务,调用编辑账务方法</span>
    <span style="color: rgba(0, 0, 0, 1)">                editZhangWu();
                    </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">case</span> 3<span style="color: rgba(0, 0, 0, 1)">:
                    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 选择的删除账务,调用删除账务方法</span>
    <span style="color: rgba(0, 0, 0, 1)">                deleteZhangWu();
                    </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">case</span> 4<span style="color: rgba(0, 0, 0, 1)">:
                    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 选择的是查询账务,调用查询方法</span>
    <span style="color: rgba(0, 0, 0, 1)">                selectZhangWu();
                    </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">case</span> 5<span style="color: rgba(0, 0, 0, 1)">:
                    System.exit(</span>0<span style="color: rgba(0, 0, 0, 1)">);
                    </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
                }
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">run方法</span></div>
    <p>2、app包MainApp类的main主方法中，调用MainView类中run方法</p>
    <div class="cnblogs_code">
    <pre> <span style="color: rgba(0, 0, 255, 1)">new</span> MainView().run();</pre>
    </div>
    <h3>查询所有账务</h3>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721105705599-129027100.png" alt=""></p>
    <p><strong>功能实现步骤</strong></p>
    <p>1&nbsp;编写MainView类中selectZhangWu方法</p>
    <ul>
    <li>通过输出语句，显示出要查询账务的方式</li>
    <li>接收键盘的输入项，调用对应的方法（1.查询所有　2.按条件查询）</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_b9f2ae40-9659-4e78-a17d-fbc2ede1ae61" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_b9f2ae40-9659-4e78-a17d-fbc2ede1ae61" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_b9f2ae40-9659-4e78-a17d-fbc2ede1ae61" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法 selectZhangWu()
         * 显示查询的方式 1 所有查询   2 条件查询
         * 接收用户的选择
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> selectZhangWu(){
             System.out.println(</span>"1. 查询所有    2. 条件查询"<span style="color: rgba(0, 0, 0, 1)">);
             Scanner sc </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in);
             </span><span style="color: rgba(0, 0, 255, 1)">int</span> selectChooser =<span style="color: rgba(0, 0, 0, 1)"> sc.nextInt();
             </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">判断根据用户的选择,调用不同的功能</span>
             <span style="color: rgba(0, 0, 255, 1)">switch</span><span style="color: rgba(0, 0, 0, 1)">(selectChooser){
             </span><span style="color: rgba(0, 0, 255, 1)">case</span> 1<span style="color: rgba(0, 0, 0, 1)">:
                 </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">选择的查询所有,调用查询所有的方法</span>
    <span style="color: rgba(0, 0, 0, 1)">             selectAll();
                 </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
             </span><span style="color: rgba(0, 0, 255, 1)">case</span> 2<span style="color: rgba(0, 0, 0, 1)">:
                 </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">选的条件查询,调用带有查询条件的方法</span>
    <span style="color: rgba(0, 0, 0, 1)">             select();
                 </span><span style="color: rgba(0, 0, 255, 1)">break</span><span style="color: rgba(0, 0, 0, 1)">;
             }
         }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">selectZhangWu方法</span></div>
    <p>2&nbsp;编写MainView类中selectAll查询所有账务方法</p>
    <ul>
    <li>调用ZhangWuService类selectAll方法，返回包含所有账务数据的List&lt;ZhangWu&gt;集合</li>
    <li>调用MainView类中print方法，实现控制台显示所有账务数据</li>
    <li>编写MainView类中print方法，使用输出语句，打印出账务表的表头名称，遍历账务集合，将每个账务信息输出打印</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_87a7336a-e47d-4fb7-8fb8-89667ce302cb" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_87a7336a-e47d-4fb7-8fb8-89667ce302cb" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_87a7336a-e47d-4fb7-8fb8-89667ce302cb" class="cnblogs_code_hide">
    <pre> <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法,实现查询所有的账务数据
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> selectAll(){
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用控制层中的方法,查询所有的账务数据</span>
            List&lt;ZhangWu&gt; list =<span style="color: rgba(0, 0, 0, 1)"> service.selectAll();
            </span><span style="color: rgba(0, 0, 255, 1)">if</span>(list.size()!=0<span style="color: rgba(0, 0, 0, 1)">)
                print(list);
            </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)">
                System.out.println(</span>"没有查询到数据"<span style="color: rgba(0, 0, 0, 1)">);
        }
    
        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出账务数据方法,接收List集合,遍历集合,输出表格</span>
        <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> print(List&lt;ZhangWu&gt;<span style="color: rgba(0, 0, 0, 1)"> list) {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出表头</span>
            System.out.println("ID\t\t类别\t\t账户\t\t金额\t\t时间\t\t说明"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">遍历集合,结果输出控制台</span>
            <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)">(ZhangWu zw : list){
                System.out.println(zw.getZwid()</span>+"\t\t"+zw.getFlname()+"\t\t"+zw.getZhanghu()+"\t\t"+<span style="color: rgba(0, 0, 0, 1)">
                        zw.getMoney()</span>+"\t\t"+zw.getCreatetime()+"\t"+<span style="color: rgba(0, 0, 0, 1)">zw.getDescription());
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">selectAll方法</span></div>
    <p>3、编写ZhangWuService类中selectAll方法</p>
    <ul>
    <li>调用ZhangWuDao类中selectAll方法，返回包含所有账务数据的List&lt;ZhangWu&gt;集合</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_32c9613d-6ca5-4b09-b28b-609ee4cfa65d" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_32c9613d-6ca5-4b09-b28b-609ee4cfa65d" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_32c9613d-6ca5-4b09-b28b-609ee4cfa65d" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         *  定义方法,实现查询所有的账务数据
         *  此方法,由控制层调用, 去调用dao层的方法
         *  返回存储ZhangWu对象的List集合
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;ZhangWu&gt;<span style="color: rgba(0, 0, 0, 1)"> selectAll(){
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> dao.selectAll();
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">selectAll方法</span></div>
    <p>4、编写ZhangWuDao类中selectAll()方法</p>
    <ul>
    <li>通过QueryRunner对象，调用query方法查询数据库表gjp_zhangwu，返回包含所有账务数据的List&lt;ZhangWu&gt;集合</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_037eb7a2-8dda-4fe5-bde4-370e76cf552a" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_037eb7a2-8dda-4fe5-bde4-370e76cf552a" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_037eb7a2-8dda-4fe5-bde4-370e76cf552a" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法,查询数据库,获取所有的账务数据
         * 方法,由业务层调用
         * 结果集,将所有的账务数据,存储到Bean对象中,存储到集合中
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;ZhangWu&gt;<span style="color: rgba(0, 0, 0, 1)"> selectAll(){
            </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">查询账务数据的SQL语句</span>
                String sql = "SELECT * FROM gjp_zhangwu"<span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用qr对象的方法,query方法,结果集BeanListHandler</span>
                List&lt;ZhangWu&gt; list = qr.query(sql, <span style="color: rgba(0, 0, 255, 1)">new</span> BeanListHandler&lt;&gt;(ZhangWu.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">));
                </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> list;
            }</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)">(SQLException ex){
                System.out.println(ex);
                </span><span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> RuntimeException("查询所有账务失败"<span style="color: rgba(0, 0, 0, 1)">);
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">selectAll方法</span></div>
    <p><strong>多条件查询账务</strong>&nbsp;</p>
    <p>1 、编写MainView类中select方法</p>
    <ul>
    <li>通过键盘输入查询日期的范围</li>
    <li>调用ZhangWuSerice类中select方法，返回查询日期范围内的账务信息集合List&lt;ZhangWu&gt;</li>
    <li>调用MainView类中的print方法，将账务信息集合中的内容显示在控制台中</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_08120257-436b-4006-9bdc-8d9e2a7acdd4" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_08120257-436b-4006-9bdc-8d9e2a7acdd4" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_08120257-436b-4006-9bdc-8d9e2a7acdd4" class="cnblogs_code_hide">
    <pre> <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法,实现条件查询账务数据
         * 提供用户的输入日期,开始日期结束日期
         * 就2个日期,传递到controller层
         * 调用controller的方法,传递2个日期参数
         * 获取到controller查询的结果集,打印出来
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> select(){
            System.out.println(</span>"选择条件查询,输入日期格式XXXX-XX-XX"<span style="color: rgba(0, 0, 0, 1)">);
            Scanner sc </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in);
            System.out.print(</span>"请输入开始日期:"<span style="color: rgba(0, 0, 0, 1)">);
            String startDate </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.nextLine();
            System.out.print(</span>"请输入结果日期:"<span style="color: rgba(0, 0, 0, 1)">);
            String endDate </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.nextLine();
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用controller层的方法,传递日期,获取查询结果集</span>
            List&lt;ZhangWu&gt; list =<span style="color: rgba(0, 0, 0, 1)"> service.select(startDate, endDate);
            </span><span style="color: rgba(0, 0, 255, 1)">if</span>(list.size()!=0<span style="color: rgba(0, 0, 0, 1)">)
                print(list);
            </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)">
                System.out.println(</span>"没有查询到数据"<span style="color: rgba(0, 0, 0, 1)">);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">select方法</span></div>
    <p>2、 编写ZhangWuService类中select方法</p>
    <ul>
    <li>调用ZhangWuDao 类中select方法，返回查询日期范围内的账务信息集合List&lt;ZhangWu&gt;</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_91864cea-f5e1-4b90-ba58-4a4bf3dfe30b" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_91864cea-f5e1-4b90-ba58-4a4bf3dfe30b" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_91864cea-f5e1-4b90-ba58-4a4bf3dfe30b" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法,实现条件查询账务
         * 方法由控制层调用,传递2个日期字符串
         * 调用dao层的方法,传递2个日期字符串
         * 获取到查询结果集
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;ZhangWu&gt;<span style="color: rgba(0, 0, 0, 1)"> select(String startDate,String endDate){
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> dao.select(startDate, endDate);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">select方法</span></div>
    <p>3&nbsp;编写ZhangWuDao类中select方法</p>
    <ul>
    <li>通过QueryRunner对象，调用query方法查询数据库表gjp_zhangwu，返回包含查询日期范围内的账务数据List&lt;ZhangWu&gt;集合</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_89782147-e92c-49a2-bbe5-dea422b1b250" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_89782147-e92c-49a2-bbe5-dea422b1b250" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_89782147-e92c-49a2-bbe5-dea422b1b250" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法,查询数据库,带有条件去查询账务表
         * 由业务层调用,查询结果集存储到Bean对象,存储到List集合
         * 调用者传递2个日期字符串
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;ZhangWu&gt;<span style="color: rgba(0, 0, 0, 1)"> select(String startDate,String endDate){
            </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">拼写条件查询的SQL语句</span>
                String sql = "SELECT * FROM gjp_zhangwu WHERE createtime BETWEEN ? AND ?"<span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">定义对象数组,存储?占位符</span>
                Object[] params =<span style="color: rgba(0, 0, 0, 1)"> {startDate,endDate};
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用qr对象的方法query查询数据表,获取结果集</span>
                <span style="color: rgba(0, 0, 255, 1)">return</span> qr.query(sql, <span style="color: rgba(0, 0, 255, 1)">new</span> BeanListHandler&lt;&gt;(ZhangWu.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">),params);
            }</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)">(SQLException ex){
                System.out.println(ex);
                </span><span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> RuntimeException("条件查询失败"<span style="color: rgba(0, 0, 0, 1)">);
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">select方法</span></div>
    <h3><strong>添加账务</strong></h3>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721110924021-650362236.png" alt=""></p>
    <p><strong>功能实现步骤</strong></p>
    <p>1 、编写MainView类中addZhangWu方法</p>
    <ul>
    <li>键盘输入新添加的账务信息</li>
    <li>调用ZhangWuService类中addZhangWu方法，用来指定账务的添加</li>
    <li>添加完毕后，使用输出语句，提示“添加账务成功！”</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_2b4e444a-1055-4b2a-aa83-443ecce5866f" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_2b4e444a-1055-4b2a-aa83-443ecce5866f" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_2b4e444a-1055-4b2a-aa83-443ecce5866f" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法addZhangWu
         * 添加账务的方法，用户在界面中选择菜单1的时候调用、
         * 实现思想：
         *       接收键盘输入，5项输入，调用controller层方法
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> addZhangWu() {
            System.out.println(</span>"选择的添加账务功能，请输入以下内容"<span style="color: rgba(0, 0, 0, 1)">);
            Scanner sc </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in);
            System.out.println(</span>"输入分类名称"<span style="color: rgba(0, 0, 0, 1)">);
            String flname </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入金额"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> money =<span style="color: rgba(0, 0, 0, 1)"> sc.nextDouble();
            System.out.println(</span>"输入账户"<span style="color: rgba(0, 0, 0, 1)">);
            String zhanghu </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入日期：格式XXXX-XX-xx"<span style="color: rgba(0, 0, 0, 1)">);
            String createtime </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入具体描述"<span style="color: rgba(0, 0, 0, 1)">);
            String description </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将接收到的数据，调用controller层的方法，传递参数，实现数据添加
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将用户输入的所有参数，封装成ZhangWu对象</span>
            ZhangWu zw = <span style="color: rgba(0, 0, 255, 1)">new</span> ZhangWu(0<span style="color: rgba(0, 0, 0, 1)">, flname, money, zhanghu, createtime, description);
            controller.addZhangWu(zw);
            System.out.println(</span>"恭喜添加账务成功"<span style="color: rgba(0, 0, 0, 1)">);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">addZhangWu方法</span></div>
    <p>2 、编写ZhangWuService类中addZhangWu方法</p>
    <ul>
    <li>调用ZhangWuDao类中addZhangWu方法，用来指定账务的添加</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_86f25131-d6e5-4ef3-9563-04c4fa65b9f9" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_86f25131-d6e5-4ef3-9563-04c4fa65b9f9" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_86f25131-d6e5-4ef3-9563-04c4fa65b9f9" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现添加账务
         * 是由控制层调用，传递ZhangWu对象
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> addZhangWu(ZhangWu zw) {
            dao.addZhangWu(zw);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">addZhangWu</span></div>
    <p>3、 编写ZhangWuDao类中addZhangWu方法</p>
    <ul>
    <li>通过QueryRunner对象，调用update方法更新数据库表gjp_zhangwu，完成指定账务添加到数据库表中</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_cb7dc323-7613-4ccb-8117-412f8a1ff39d" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_cb7dc323-7613-4ccb-8117-412f8a1ff39d" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_cb7dc323-7613-4ccb-8117-412f8a1ff39d" class="cnblogs_code_hide">
    <pre> <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现添加账务功能
         * 由业务层调用，传递ZhangWu对象
         * 将ZhangWu对象中的数据，添加到数据库
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> addZhangWu(ZhangWu zw) {
            </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">拼接添加数据的sql</span>
                String sql = "INSERT INTO gjp_zhangwu (flname,money,zhanghu,createtime,description) VALUES(?,?,?,?,?)"<span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建对象数组，处处5个占位符的实际参数
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">实际参数来源是传递过来的对象ZhangWu</span>
                Object[] params =<span style="color: rgba(0, 0, 0, 1)"> {zw.getFlname(),zw.getMoney(),zw.getZhanghu(),zw.getCreatetime(),zw.getDescription()};
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用qr对象中的方法update执行添加</span>
    <span style="color: rgba(0, 0, 0, 1)">            qr.update(sql, params);
            }</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)">(SQLException ex) {
                System.out.println(ex);
                </span><span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> RuntimeException("账务添加失败"<span style="color: rgba(0, 0, 0, 1)">);
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">addZhangWu</span></div>
    <h3><strong>编辑账务</strong></h3>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721111345974-1799515087.png" alt=""></p>
    <p><strong>功能实现步骤</strong></p>
    <p>1 、编写MainView类中editZhangWu方法</p>
    <ul>
    <li>键盘输入要编辑的账务信息ID号</li>
    <li>键盘输入要修改的账务信息内容</li>
    <li>调用ZhangWuService类中editZhangWu方法，用来将指定的账务信息进行更新</li>
    <li>更新完毕后，使用输出语句，提示 “编辑账务成功！”</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_a930e820-e98a-4030-82c2-07b432d23562" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_a930e820-e98a-4030-82c2-07b432d23562" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_a930e820-e98a-4030-82c2-07b432d23562" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现对账务的编辑功能
         * 实现思想：
         *     接收用户的输入的信息
         *  封装成ZhangWu对象
         *  调用控制层的方法，传递ZhangWu对象，实现编辑
         * 
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> editZhangWu() {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用查询所有账务数据的功能，显示出来
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">看到所有数据，从中选择一项，进行修改</span>
    <span style="color: rgba(0, 0, 0, 1)">        selectAll();
            System.out.println(</span>"选择的是编辑功能，请输入数据"<span style="color: rgba(0, 0, 0, 1)">);
            Scanner sc </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in);
            System.out.print(</span>"请输入ID"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> zwid =<span style="color: rgba(0, 0, 0, 1)"> sc.nextInt();
            System.out.println(</span>"输入分类名称"<span style="color: rgba(0, 0, 0, 1)">);
            String flname </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入金额"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> money =<span style="color: rgba(0, 0, 0, 1)"> sc.nextDouble();
            System.out.println(</span>"输入账户"<span style="color: rgba(0, 0, 0, 1)">);
            String zhanghu </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入日期：格式XXXX-XX-xx"<span style="color: rgba(0, 0, 0, 1)">);
            String createtime </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            System.out.println(</span>"输入具体描述"<span style="color: rgba(0, 0, 0, 1)">);
            String description </span>=<span style="color: rgba(0, 0, 0, 1)"> sc.next();
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将用户输入的数据，封装到ZhangWu对象中
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">用户输入的ID，必须封装到到对象中</span>
            ZhangWu zw = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> ZhangWu(zwid, flname, money, zhanghu, createtime, description);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用controller层中的方法，实现编辑账务</span>
    <span style="color: rgba(0, 0, 0, 1)">        controller.editZhangWu(zw);
            System.out.println(</span>"账务编辑成功"<span style="color: rgba(0, 0, 0, 1)">);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">editZhangWu</span></div>
    <p>2 、编写ZhangWuService类中editZhangWu方法</p>
    <ul>
    <li>调用ZhangWuDao类中editZhangWu方法，用来将指定的账务信息进行更新</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_9edee0db-13d3-4d65-b4e2-4bd2f5efaf6c" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_9edee0db-13d3-4d65-b4e2-4bd2f5efaf6c" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_9edee0db-13d3-4d65-b4e2-4bd2f5efaf6c" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现编辑账务
         * 由控制层调用，传递ZhangWu对象
         * 调用dao层的方法，传递ZhangWu对象
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> editZhangWu(ZhangWu zw) {
            dao.editZhangWu(zw);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">editZhangWu方法</span></div>
    <p>3 、编写ZhangWuDao类中editZhangWu方法</p>
    <ul>
    <li>通过QueryRunner对象，调用update方法更新数据库表gjp_zhangwu，完成数据库表中指定账务更新操作</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_16d88d38-09fe-40cd-9ad6-26d8ad9778f8" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_16d88d38-09fe-40cd-9ad6-26d8ad9778f8" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_16d88d38-09fe-40cd-9ad6-26d8ad9778f8" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现编辑功能
         * 由业务层调用，传递ZhangWu对象
         * 将对象中的数据，更新到数据表
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> editZhangWu(ZhangWu zw) {
            </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">更新数据的SQL</span>
                String sql = "UPDATE gjp_zhangwu SET flname=?,money=?,zhanghu=?,createtime=?,description=? WHERE zwid=?"<span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">定义对象数组，封装所有数据</span>
                Object[] params =<span style="color: rgba(0, 0, 0, 1)"> {zw.getFlname(),zw.getMoney(),zw.getZhanghu(),zw.getCreatetime(),zw.getDescription(),zw.getZwid()};
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用qr对象方法update执行更新</span>
    <span style="color: rgba(0, 0, 0, 1)">            qr.update(sql, params);
            } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (SQLException ex) {
                System.out.println(ex);
                </span><span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> RuntimeException("编辑账务失败"<span style="color: rgba(0, 0, 0, 1)">);
            }
            
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">editZhangWu方法</span></div>
    <p><strong><span style="font-family: 宋体">删除账务</span></strong></p>
    <p>&nbsp;<img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170721112949380-915396053.png" alt=""></p>
    <p><strong style="font-size: 1em">功能实现步骤</strong></p>
    <p>1 、编写MainView类中deleteZhangWu方法</p>
    <ul>
    <li>键盘输入要删除的账务信息ID号</li>
    <li>调用ZhangWuService类中deleteZhangWu方法，用来将指定的账务信息删除</li>
    <li>删除完毕后，使用输出语句，提示 “删除账务成功！”</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_4678f8e5-c3da-40a1-9a08-828d0ad8a377" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_4678f8e5-c3da-40a1-9a08-828d0ad8a377" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_4678f8e5-c3da-40a1-9a08-828d0ad8a377" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现账务删除
         * 实现思想：
         *     接收用户的输入，输入一个主键数据
         *  调用控制层方法，传递一个主键
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> deleteZhangWu() {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用查询所有账务数据的功能，显示出来
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">看到所有数据，从中选择一项，进行修改</span>
    <span style="color: rgba(0, 0, 0, 1)">        selectAll();
            System.out.println(</span>"选择的是删除功能，请输入序号即可"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> zwid = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Scanner(System.in).nextInt();
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用控制层方法，传递主键id即可</span>
    <span style="color: rgba(0, 0, 0, 1)">        controller.deleteZhangWu(zwid);
            System.out.println(</span>"删除账务成功"<span style="color: rgba(0, 0, 0, 1)">);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">deleteZhangWu方法</span></div>
    <p>2 、编写ZhangWuService类中deleteZhangWu方法</p>
    <ul>
    <li>调用ZhangWuDao类中deleteZhangWu方法，用来将指定的账务信息删除</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_8f6aa33d-3ad6-4789-ab39-8151e1311851" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_8f6aa33d-3ad6-4789-ab39-8151e1311851" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_8f6aa33d-3ad6-4789-ab39-8151e1311851" class="cnblogs_code_hide">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现删除账务功能
         * 由控制层调用，传递主键id
         * 调用dao层方法，传递主键id
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> deleteZhangWu(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> zwid) {
            dao.deleteZhangWu(zwid);
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">deleteZhangWu方法</span></div>
    <p>3 、编写ZhangWuDao类中deleteZhangWu方法</p>
    <ul>
    <li>通过QueryRunner对象，调用update方法更新数据库表gjp_zhangwu，完成数据库表中指定账务删除操作</li>
    </ul>
    <div class="cnblogs_code"><img id="code_img_closed_10b077ec-95f5-4e62-8987-5ca95bcc407f" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_10b077ec-95f5-4e62-8987-5ca95bcc407f" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
    <div id="cnblogs_code_open_10b077ec-95f5-4e62-8987-5ca95bcc407f" class="cnblogs_code_hide">
    <pre> <span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">
         * 定义方法，实现删除业务
         * 业务层调用，传递主键id
         </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
        <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span> deleteZhangWu(<span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> zwid) {
            </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">拼写删除数据SQL</span>
                String sql = "DELETE FROM gjp_zhangwu WHERE zwid=?"<span style="color: rgba(0, 0, 0, 1)">;
                qr.update(sql, zwid);
            } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (SQLException ex) {
                System.out.println(ex);
                </span><span style="color: rgba(0, 0, 255, 1)">throw</span> <span style="color: rgba(0, 0, 255, 1)">new</span> RuntimeException("删除账务失败"<span style="color: rgba(0, 0, 0, 1)">);
            }
        }</span></pre>
    </div>
    <span class="cnblogs_code_collapse">deleteZhangWu</span></div>
    <h2>功能模块总结</h2>
    <p>到此为止，已经完成了分类模块所有功能。通过分类模块功能的实现，大家可能会发现如下几个问题：</p>
    <p>难度大的地方：自行功能分析的能力欠缺；</p>
    <p>代码实现：</p>
    <ul>
    <li>View（Controller）：代码量最大；</li>
    <li>Service层：代码量最小；</li>
    <li>DAO层：相似度高，难度不大；</li>
    </ul>
    <p>view层的作用是“界面”，用来完成数据显示给用户。当前项目view层中，包含了Controller层代码。</p>
    <p>Controller层的作用是“调度”，调度的是表现层view和业务层Service，主要功能分为：一是把表现层的数据交给业务层处理；二是把业务层返回的数据交给表现层显示。至于为什么这一层View（Controller）的代码量大，这里我要说明一下，其实不是View（Controller）层的代码量大，而是其他层代码量少，所以你会感觉View（Controller）层代码量大。</p>
    <p>Service层的作用是“业务”，我们也可以把“业务”当成是“功能”。那为什么Service层代码量少呢？原因是现在我们写的项目很小，没有什么复杂的业务，而今后大家要写的大型项目代码量最大的就是Service层。</p>
    <p>DAO层是操作数据库，现在我们使用的是commons-dbutils工具来简化JDBC，所以我们发现代码不多，比较简单。最后我们还会学习其他DAO层的工具，例如：hibernate和mybatis，他们都是JDBC的封装，用来简化JDBC。</p>
    <p><a href="http://files.cnblogs.com/files/ginb/gjp.zip" target="_blank">&nbsp;源码</a></p>
    </div>

</body>
</html>